import ServiceBase from '../base';
import {FolderPagePermissionProxy, FolderPermissionProxy} from '../proxies/auth-proxy';
import * as proxy from '../proxy';

const GET_ACCOUNTS = '/accounts';

class PermissionService extends ServiceBase {
    getPermit = (data) => {
        let promise = super.get({
            url:
                GET_ACCOUNTS +
                `/${data.accountId}/projects/${data.projectId}/folders/${data.folderId}/privileges`,
        });
        return proxy.httpResultProxy(promise, FolderPagePermissionProxy);
    };
    getFolderPermit = (data) => {
        let promise = super.get({
            url:
                GET_ACCOUNTS +
                `/${data.accountId}/projects/${data.projectId}/folders/${data.folderId}/privileges/me/info`,
        });
        return proxy.httpResultProxy(promise, FolderPermissionProxy);
    };
    getFilePermit = (data) => {
        let promise = super.get({
            url:
                GET_ACCOUNTS +
                `/${data.accountId}/projects/${data.projectId}/files/${data.fileId}/privileges/me/info`,
        });
        return proxy.httpResultProxy(promise, FolderPermissionProxy);
    };
    postPermit = (data) => {
        let promise = super.post({
            url:
                GET_ACCOUNTS +
                `/${data.accountId}/projects/${data.projectId}/folders/${data.folderId}/privileges`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise);
    };
    putPermit = (data) => {
        let promise = super.put({
            url:
                GET_ACCOUNTS +
                `/${data.accountId}/projects/${data.projectId}/folders/${data.folderId}/privileges`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise);
    };
    // /accounts/{accountId}/projects/{projectId}/folders/{folderId}/privileges/{privilegeId} 删除一个 Folder 下的 Privilege
    deletePermit = (data) => {
        let promise = super.delete({
            url:
                GET_ACCOUNTS +
                `/${data.accountId}/projects/${data.projectId}/folders/${data.folderId}/privileges/${
                    data.privilegeId
                }`,
        });
        return proxy.httpResultProxy(promise);
    };
    // PUT /accounts/{accountId}/projects/{projectId}/files/{fileId}/locking  对指定的 Project 下的 File 锁信息进行修改
    putLocking = (data) => {
        let promise = super.put({
            url: GET_ACCOUNTS + `/${data.accountId}/projects/${data.projectId}/files/${data.fileId}/locking`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise);
    };
}

export {PermissionService};
